﻿@using VideoSeller.Business.Data.Enums
@using VideoSeller.Business.Models
@using VideoSeller.Core.Configuration
@using System
@model ContentListViewModel

@functions {
    readonly WaitModel _waitModel = IoC.Resolve<WaitModel>();

    bool IsWantToSee(int onlineContentId)
    {
        return _waitModel.IsWantToSee(onlineContentId, Model.CurrentMembershipUser.UserId);
    }
}

@*@if (Model.Items.Any() && Model.CurrentMembershipUser != null && !Model.CurrentMembershipUser.IsAnonymous && (Model.FilterViewModel != null && Model.FilterViewModel.Controller != "Cabinet"))
{
	<div style="float: right">
		@Html.GetGlobalResource("ContentList", "WantToSee")
	</div>
	<div class="ui-helper-clearfix"></div>
}*@


<div id="_prePLAYBlock" style="display:none; position:absolute; z-index:99; top:0px; left:0px; width:242px; height:137px;">
<script type="text/jscript">
	if (AC_FL_RunContent == 0) {
		alert("This page requires AC_RunActiveContent.js.");
	} else {
		addpplayer('prePLAY', 'rtmp://visell.tv/VSlive', '@Model.CurrentUserId', '@Model.CurrentSessionId', '0', '');
		}
	</script>
	<div style="display:none;">
	<div id="_prePLAY_stopbtn"></div>
					<div id="_prePLAY_playbtn"></div>
					<label  id="_prePLAY_msg"></label>
					</div>

</div>
@{
       
        Boolean iOwner = false;
		String iurl = "";
        String ourl = "";
		String pws = "____ere77__9";
 }
@foreach (var item in Model.Items)
{
    iOwner = item.Client.UserId == Model.CurrentUserId;

	if (!String.IsNullOrEmpty(item.Password))
	{
		pws = item.Password;
	}
	iurl = Model.WowzaPatch + "VSLive?" + Model.CurrentUserId + "&" + Model.CurrentSessionId + "&"+item.Id+"&"+pws + "/" + item.Id;
    ourl = "<iframe src=\"http://www.visell.tv/home/content/"+item.Id+"?fr=1\" frameborder=\"no\"  scrolling = \"no\" width=\"890\" height=\"650\"	style=\"margin-left:auto; margin-right:auto;\"></iframe>";
	<div id="content-@item.Id" class="vline"></div>

    
               <div class ="content_list_block">
        <table >
            <tr>
                <td class="c_l_col1">
                    <img src='@Url.Content(string.Format("~/content/images/video_type_{0}.png", @item.VideoContentType.ToString()))'  class="c_d_big_field c_d_tr_type np"/>
                    @if (item.Price > 0)
                    {
                     <img alt="paid" src='@Url.Content(string.Format("~/content/images/many.png", @item.VideoContentType.ToString()))'  class="c_d_big_field c_d_tr_type np"/>   
                    }
                    @if (!String.IsNullOrEmpty(item.Password))
                    {
                     <img alt="Pass" src='@Url.Content(string.Format("~/content/images/closed.png", @item.VideoContentType.ToString()))'  class="c_d_big_field c_d_tr_type np"/>   
                    } 
 
                </td>
                <td class="c_l_col2">
                    <a href="@Url.Action("Content", "Home", new { id = item.Id })">
                    <img  src="@Url.GetThumbnailImage(item.ImageUrl, ThumbnailImageSize.Small)" class="vimg" alt="@item.Title"/>
                        </a>
                    <div class="control_buttons">
                        @if (!item.Active && iOwner && (Model.FilterViewModel != null && Model.FilterViewModel.Controller == "Cabinet"))
                        {
                            <a class="vs_btn_del flr " href="javascript:void(0);" onclick="if (this.innerHTML=='Wait...') return false; this.innerHTML='Wait...'; DeleteContent('@item.Id');">@Html.GetGlobalResource("Common", "Delete")</a> 

                            if (item.OnlineContentType != OnlineContentType.History)
                            {			
                                <a class="vs_btn_edt flr" href="javascript:void(0);" onclick=" EditContent('@item.Id'); ">@Html.GetGlobalResource("Common", "Edit")</a>
                            }
                        }
                    </div>
                </td>
                <td class="c_l_col3">
                    <img src='@Url.Content(item.CultureImage)' class=" fll" />
					<div class="c_d_small_field c_l_title fll elipsiss">@item.Title</div>
                    
                    <div style="clear: both;"></div>
				
                    <div style="clear: both;"></div>
                    <div class="c_d_small_field c_l_dsc list_descript" title="@item.Description">@item.Description</div>
                   
                    <div style="clear: both;"></div>
                    <div class="c_d_small_field c_l_field2 fll elipsiss"  title="@item.Client.Login"><a href="@Url.Action("Profile", "Client", new { id = item.Client.UserId })">@item.Client.Login</a></div>                    
                    <div class="c_d_small_field c_l_field2 fll" >
					@if (item.VideoContentType == VideoContentType.Free)
					{
						<span class="c_l_fields">@item.Client.m_Rating.ToString()</span>
					}

					@if (item.VideoContentType == VideoContentType.Paid)
					{
						<span class="c_l_fieldm">@item.Client.c_Rating.ToString()</span>
					}

                    </div>
                     @if (item.Price > 0)
                     {<div class="c_d_small_field flr price_in_list">@Html.GetGlobalResource("Common", "Price"): @Html.GetCurrencyString(item.Price)</div>}
                     else
                     {<div class="c_d_small_field flr price_in_list">@Html.GetGlobalResource("Common", "FreeContent")</div>}
                    <div class="c_d_small_field c_l_field2 fll elipsiss"  title="@item.Country.Name">@item.Country.Name</div>
                    @if (iOwner && (Model.FilterViewModel != null && Model.FilterViewModel.Controller == "Cabinet"))
                    {
                      <div class="c_d_small_field flr price_in_list">@Html.GetGlobalResource("Common", "MarkedContent"):&nbsp @item.WaitCount.ToString()</div>
                    }
                </td>
                <td class="c_l_col4">
                @if (item.isWaitingStart)
                {
                    <div class="c_d_small_field c_l_field1 hasCountdown">
                        @{var diff = item.broadcastStart - DateTime.Now;
                            if (diff.TotalSeconds < 0)
                            {
                            <label>@Html.GetGlobalResource("Common", "WaitingContent")</label>
                        }
                        else
                        {
                            <div id="@(string.Concat("countdown", item.Id))"></div>
                            <script type="text/javascript">

                                var untilVal = parseInt("@diff.TotalSeconds");
                                $("#countdown" + "@item.Id").countdown({ until: +untilVal, compact: true });
                            </script>
                        }
                        }
                    </div>
                  }

                   @if (item.Active)
                   {
                       <div class="c_d_small_field c_l_field1">
                           @{
                       var diff = item.broadcastStart;
                               <div id="@(string.Concat("countup", item.Id))" style="color:green !important;"></div>
                               <script type="text/javascript">
                                   var dtt = new Date(parseInt(@diff.Year), parseInt(@diff.Month-1), parseInt(@diff.Day), parseInt(@diff.Hour), parseInt(@diff.Minute), parseInt(@diff.Second));
                                   $("#countup" + "@item.Id").countdown({ since: dtt, compact: true });						</script>}
                       </div>
                   }
                          

                    @if(item.OnlineContentType == OnlineContentType.History)
	                {
                                <div class="c_d_small_field c_l_field1 hasCountdown" style="color:black;">@item.lenHistory</div>
	                }

                    <div class="c_d_small_field c_l_field1">
                        <img title='@Html.GetGlobalResource("MainTabs", "Announcement")' src='@Url.Content("~/content/images/view_a.png")' width="18" height="18" class="np"/>
                        @item.Views_anonce.ToString()</div>
					@if (item.OnlineContentType != OnlineContentType.Announcement)
	 {
                    <div class="c_d_small_field c_l_field1">
                        <img  title='@Html.GetGlobalResource("MainTabs", "Online")' src='@Url.Content("~/content/images/view.png")' width="18" height="18" class="np"/>
                        @item.Views_online.ToString()</div>}
					@if(item.OnlineContentType == OnlineContentType.History){															
                    <div class="c_d_small_field c_l_field1">
                        <img  title='@Html.GetGlobalResource("MainTabs", "History")' src='@Url.Content("~/content/images/view_h.png")' width="18" height="18" class="np"/>
                        @item.Views_history.ToString()</div>
			}
                    @{string mar = string.Empty;
                      int height = 19;
                      if (item.isWaitingStart) {mar = (height * 3).ToString();}
                      if (item.Active) { mar = (height * 2-1).ToString(); }
                      if (item.OnlineContentType == OnlineContentType.History) { mar = (height-3).ToString(); }
                      mar += "px";
                    }

                    @if (item.Price > 0)
                    {

                       
                        <div class="c_d_small_field c_l_field1 collected" style="margin-top:@mar">
                            <img src="~/Content/images/many.png" class="vsm" />&nbsp;@Html.GetCurrencyString(item.CollectedMoney)</div>
                    }
                </td>
                <td class="c_l_col5">
			
			@if (Model.CurrentMembershipUser != null && !Model.CurrentMembershipUser.IsAnonymous && (Model.FilterViewModel != null && Model.FilterViewModel.Controller != "Cabinet"))
   {
			<div style="float: right;">
				<input type="checkbox" title="@Html.GetGlobalResource("ContentList", "WantToSee")" onclick="@(string.Format("MarkOnlineContent('{0}', $(this));", item.Id))" @(IsWantToSee(item.Id) ? "checked=\"checked\"" : string.Empty) />
			</div>
   }
       @* @if (!item.Active && iOwner && (Model.FilterViewModel != null && Model.FilterViewModel.Controller == "Cabinet"))
        {
   
			                    if (item.OnlineContentType != OnlineContentType.History)
                       {			
                                <a class="vs_btn_edt flr" href="javascript:void(0);" onclick=" EditContent('@item.Id'); ">@Html.GetGlobalResource("Common", "Edit")</a>
                       }

						<a class="vs_btn_del flr " href="javascript:void(0);" onclick="if (this.innerHTML=='Wait...') return false; this.innerHTML='Wait...'; DeleteContent('@item.Id');">@Html.GetGlobalResource("Common", "Delete")</a> 
        }*@
        
                </td>
            </tr>
	@if (Model.CurrentMembershipUser != null && !Model.CurrentMembershipUser.IsAnonymous && (Model.FilterViewModel != null && Model.FilterViewModel.Controller == "Cabinet") && item.VideoContentType == VideoSeller.Business.Data.Enums.VideoContentType.Free)
	{
		<tr>
			<td colspan="1"><div class="vs_btn ibutton" onclick ='chDisplay("cpd-@item.Id")'>i</div></td>
            <td colspan="1"><div class="vs_btn ibutton" onclick ='chDisplay("cpo-@item.Id")'>@Html.GetGlobalResource("Common", "ExternalLink")</div></td>
            <td colspan="3"></td>
		</tr>
	 <tr><td colspan="5"><textarea class="outarea" readonly id ="cpd-@item.Id" >@iurl</textarea></td></tr>
	 <tr><td colspan="5"><textarea class="outarea" readonly  id ="cpo-@item.Id" >@ourl</textarea></td></tr>	}

        </table>
            </div>


     
    
	
	<div style="clear:both;"></div>
}

@if (Model.FilterViewModel.Total > 10)
{
	<div class="ui-helper-clearfix"></div>
	<ul class="paging">
		@Html.Paging(Model.FilterViewModel.PageNumber, Model.FilterViewModel.PageCount, x => Url.Action(Model.FilterViewModel.Action, Model.FilterViewModel.Controller, new
{
    page = x,
    pageSize = Model.FilterViewModel.PageSize,
    languages = Model.FilterViewModel.Filter.Languages,
    categories = Model.FilterViewModel.Filter.Categories,
    selectedCountry = Model.FilterViewModel.SelectedCountry,
    author = Model.FilterViewModel.Filter.Author,
    search = Model.FilterViewModel.Filter.Search,
    priceFilter = Model.FilterViewModel.PriceFilter,
    filterType = Model.FilterViewModel.CurrentFilter,
    videoType = Model.FilterViewModel.VideoTypeFilter.HasValue ? Model.FilterViewModel.VideoTypeFilter.Value.ToString() : string.Empty
}))
	</ul>
	<div class="ui-helper-clearfix"></div>
	<div style="padding: 5px;">
		выводить по <a href="@Url.Action(Model.FilterViewModel.Action, Model.FilterViewModel.Controller, new
                  {
                      pageSize = 10,
                      languages = Model.FilterViewModel.Filter.Languages,
                      categories = Model.FilterViewModel.Filter.Categories,
                      selectedCountry = Model.FilterViewModel.SelectedCountry,
                      author = Model.FilterViewModel.Filter.Author,
                      search = Model.FilterViewModel.Filter.Search,
                      priceFilter = Model.FilterViewModel.PriceFilter,
                      filterType = Model.FilterViewModel.CurrentFilter,
                      videoType = Model.FilterViewModel.VideoTypeFilter.HasValue ? Model.FilterViewModel.VideoTypeFilter.Value.ToString() : string.Empty
                  })">10</a>&nbsp;&nbsp;
		<a href="@Url.Action(Model.FilterViewModel.Action, Model.FilterViewModel.Controller, new
      {
          pageSize = 30,
          languages = Model.FilterViewModel.Filter.Languages,
          categories = Model.FilterViewModel.Filter.Categories,
          selectedCountry = Model.FilterViewModel.SelectedCountry,
          author = Model.FilterViewModel.Filter.Author,
          search = Model.FilterViewModel.Filter.Search,
          priceFilter = Model.FilterViewModel.PriceFilter,
          filterType = Model.FilterViewModel.CurrentFilter,
          videoType = Model.FilterViewModel.VideoTypeFilter.HasValue ? Model.FilterViewModel.VideoTypeFilter.Value.ToString() : string.Empty
      })">30</a>&nbsp;&nbsp;
		@if (Model.FilterViewModel.Total > 30)
  {
			<a href="@Url.Action(Model.FilterViewModel.Action, Model.FilterViewModel.Controller, new
       {
           pageSize = 50,
           languages = Model.FilterViewModel.Filter.Languages,
           categories = Model.FilterViewModel.Filter.Categories,
           selectedCountry = Model.FilterViewModel.SelectedCountry,
           author = Model.FilterViewModel.Filter.Author,
           search = Model.FilterViewModel.Filter.Search,
           priceFilter = Model.FilterViewModel.PriceFilter,
           filterType = Model.FilterViewModel.CurrentFilter,
           videoType = Model.FilterViewModel.VideoTypeFilter.HasValue ? Model.FilterViewModel.VideoTypeFilter.Value.ToString() : string.Empty
       })">50</a>
  }
	</div>
}